/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package xsystems.GUI;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import xsystems.parserFile.MyUtility;

/**
 *
 * @author Rafael Tosta
 */
public class SetParameters extends javax.swing.JDialog {

    private String nome;
    private PanelFreeSpacePathLoss panelFreeSpacePathLoss;
    private PanelFreeSpaceReceivedPower panelFreeSpaceReceivedPower;
    private PanelLogDistance panelLogDistance;
    private PanelTwoRaysPathLoss panelTwoRaysPathLoss;
    private PanelHataPathLoss panelHataPathLoss;
    private PanelTwoRaysReceivedPower panelTwoRaysReceivedPower;
    private Principal parent;

    /**
     * Creates new form SetParameters
     */
    public SetParameters(Principal parent, boolean modal) {
        super(parent, modal);
        initComponents();

        this.parent = parent;
        nome = parent.modeloParametros();
        this.setTitle("Set parameter: " + nome);
        this.jLabelTitle.setText(nome);

        setPanel();
    }

    private void setPanel() {
        if (nome.equals("Free Space (PathLoss)")) {

            panelFreeSpacePathLoss = new PanelFreeSpacePathLoss();

            ArrayList<String> lerParametros = MyUtility.lerParametros(nome);
            if (lerParametros != null) {
                panelFreeSpacePathLoss.setParametros(lerParametros.get(0), lerParametros.get(1));
            }

            this.jPanelParameters.removeAll();
            this.jPanelParameters.add(panelFreeSpacePathLoss);
            this.jPanelParameters.revalidate();
            this.jPanelParameters.repaint();
        }

        if (nome.equals("Free Space (Received Power)")) {

            panelFreeSpaceReceivedPower = new PanelFreeSpaceReceivedPower();

            ArrayList<String> lerParametros = MyUtility.lerParametros(nome);
            if (lerParametros != null) {
                panelFreeSpaceReceivedPower.setParametros(lerParametros.get(0), lerParametros.get(1), lerParametros.get(2), lerParametros.get(3), lerParametros.get(4), lerParametros.get(5));
            }

            this.jPanelParameters.removeAll();
            this.jPanelParameters.add(panelFreeSpaceReceivedPower);
            this.jPanelParameters.revalidate();
            this.jPanelParameters.repaint();
        }

        if (nome.equals("Log Distance")) {

            panelLogDistance = new PanelLogDistance();

            ArrayList<String> lerParametros = MyUtility.lerParametros(nome);
            if (lerParametros != null) {
                panelLogDistance.setParametros(lerParametros.get(0), lerParametros.get(1), lerParametros.get(2), lerParametros.get(3));
            }

            this.jPanelParameters.removeAll();
            this.jPanelParameters.add(panelLogDistance);
            this.jPanelParameters.revalidate();
            this.jPanelParameters.repaint();
        }

        if (nome.equals("Two Rays (PathLoss)")) {

            panelTwoRaysPathLoss = new PanelTwoRaysPathLoss();

            ArrayList<String> lerParametros = MyUtility.lerParametros(nome);
            if (lerParametros != null) {
                panelTwoRaysPathLoss.setParametros(lerParametros.get(0), lerParametros.get(1), lerParametros.get(2), lerParametros.get(3), lerParametros.get(4));
            }

            this.jPanelParameters.removeAll();
            this.jPanelParameters.add(panelTwoRaysPathLoss);
            this.jPanelParameters.revalidate();
            this.jPanelParameters.repaint();
        }
        
         if (nome.equals("Hata (PathLoss)")) {

            panelHataPathLoss = new PanelHataPathLoss();

            ArrayList<String> lerParametros = MyUtility.lerParametros(nome);
            if (lerParametros != null) {
                panelHataPathLoss.setParametros(lerParametros.get(0), lerParametros.get(1), lerParametros.get(2), lerParametros.get(3));
            }

            this.jPanelParameters.removeAll();
            this.jPanelParameters.add(panelHataPathLoss);
            this.jPanelParameters.revalidate();
            this.jPanelParameters.repaint();
        }

        if (nome.equals("Two Rays (Received Power)")) {

            panelTwoRaysReceivedPower = new PanelTwoRaysReceivedPower();

            ArrayList<String> lerParametros = MyUtility.lerParametros(nome);
            if (lerParametros != null) {
                panelTwoRaysReceivedPower.setParametros(lerParametros.get(0), lerParametros.get(1), lerParametros.get(2), lerParametros.get(3), lerParametros.get(4), lerParametros.get(5));
            }

            this.jPanelParameters.removeAll();
            this.jPanelParameters.add(panelTwoRaysReceivedPower);
            this.jPanelParameters.revalidate();
            this.jPanelParameters.repaint();
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabelTitle = new javax.swing.JLabel();
        jPanelParameters = new javax.swing.JPanel();
        jButtonOk = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jLabelTitle.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabelTitle.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabelTitle.setText("jLabel1");

        jPanelParameters.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jButtonOk.setText("Ok");
        jButtonOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonOkActionPerformed(evt);
            }
        });

        jButton2.setText("Cancel");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(48, Short.MAX_VALUE)
                .addComponent(jPanelParameters, javax.swing.GroupLayout.PREFERRED_SIZE, 453, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50))
            .addGroup(layout.createSequentialGroup()
                .addGap(168, 168, 168)
                .addComponent(jButtonOk)
                .addGap(82, 82, 82)
                .addComponent(jButton2)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jButton2, jButtonOk});

        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelTitle)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanelParameters, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 216, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonOk)
                    .addComponent(jButton2))
                .addGap(32, 32, 32))
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOkActionPerformed
        String[] parameters = null;
        if (nome.equals("Free Space (PathLoss)")) {
            parameters = panelFreeSpacePathLoss.getParameters();
        }
        if (nome.equals("Free Space (Received Power)")) {
            parameters = panelFreeSpaceReceivedPower.getParameters();
        }
        if (nome.equals("Log Distance")) {
            parameters = panelLogDistance.getParameters();
        }
        if (nome.equals("Two Rays (PathLoss)")) {
            parameters = panelTwoRaysPathLoss.getParameters();
        }
        if (nome.equals("Hata (PathLoss)")) {
            parameters = panelHataPathLoss.getParameters();
        }
        if (nome.equals("Two Rays (Received Power)")) {
            parameters = panelTwoRaysReceivedPower.getParameters();
        }

        if (parameters != null) {
            MyUtility.gravaParametros(nome, parameters);
            parent.recuperaParametros();
            this.hide();
        } else {
            JOptionPane.showMessageDialog(this, "Insert numbers!", "Error", 0);
        }


    }//GEN-LAST:event_jButtonOkActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        this.hide();
    }//GEN-LAST:event_jButton2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButtonOk;
    private javax.swing.JLabel jLabelTitle;
    private javax.swing.JPanel jPanelParameters;
    // End of variables declaration//GEN-END:variables
}
